﻿using BUS;
using DAO;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls; 

namespace OnlineDigitalCameraWebsite
{
    public partial class ChiTiet : System.Web.UI.Page
    {
        protected List<ImagesCamera> listImageCamera = new List<ImagesCamera>();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string cate = Request.QueryString["cate"].ToString();
                int id = int.Parse(Request.QueryString["id"].ToString());
                LoadDuLieu(cate, id);
                ImagesCameraBUS imagesB = new ImagesCameraBUS();
                listImageCamera = imagesB.GetListByCamera(id);

                //dtAcc.Visible = false;
                //dtLens.Visible = false;
                //dtMayAnh.Visible = false;
                //pnCamera.Visible = false;
                //pnAcc.Visible = false;
                //pnLens.Visible = false;
            }
        }

        private void LoadDuLieu(string cate, int id)
        {
            if (cate == "camera")
            {
                // lay danh sach camera
                CameraBUS cB = new CameraBUS();
                dtMayAnh.DataSource = cB.GetListTop10();
                dtMayAnh.DataBind();

                // load thong tin
                Camera c = new Camera();
                c = cB.GetById(id);
                lblName.Text = c.camNames;
                lblPrice.Text =  string.Format(System.Globalization.CultureInfo.CreateSpecificCulture("vi-VN"), "{0:#,## VNĐ}",  c.camPrice);
                lblDetails.Text = c.camDetails;
                lblcamMaxResolution.Text = c.camMaxResolution;
                lblcamSensorSize.Text = c.camSensorSize;
                lblcamSensorType.Text = c.camSensorType;
                lblcamIso.Text = c.camIso;
                lblcamFocalLengthMulti.Text = c.camFocalLengthMulti;
                lblcamScreenSize.Text = c.camScreenSize;
                lblcamMinShutterSpeed.Text = c.camMinShutterSpeed;
                lblcamMaxShutterSpeed.Text = c.camMaxShutterSpeed;
                lblModel.Text = c.Model.modelNames;
                lblmanufacturerId.Text = c.Manufacturer.manufacturerNames;
                lblseriesId.Text = c.Series.seriesNames;
                imghinh.ImageUrl = c.camImages;
                 

                 dtMayAnh.Visible = true;
                 pnCamera.Visible = true;
                 dtMayAnh.DataBind();
                 pnCamera.DataBind();
            }
            else if (cate == "lens")
            {
                // lay danh sach lens
                LensBUS cB = new LensBUS();
                dtLens.DataSource = cB.GetListTop10();
                dtLens.DataBind();

                // load thong tin
                Lens c = new Lens();
                c = cB.GetById(id);
                lblName.Text = c.lensNames;
                lblPrice.Text = string.Format(System.Globalization.CultureInfo.CreateSpecificCulture("vi-VN"), "{0:#,## VNĐ}", c.lensPrice);
                lblDetails.Text = c.lensDetails;

                lbllensFocallensgth.Text = c.lensFocallensgth;
                lbllensMaxaperture.Text = c.lensMaxaperture;
                lbllensMinaperture.Text = c.lensMinaperture;
                lbllensMinfocus.Text = c.lensMinfocus;
                lbllensMaxmagnification.Text = c.lensMaxmagnification;
                imghinh.ImageUrl = c.lensImages;

                dtLens.Visible = true;
                pnLens.Visible = true;
                dtLens.DataBind();
                pnLens.DataBind();
              
            }
            else if (cate == "accessories")
            {
                AccessoriesBUS cB = new AccessoriesBUS();
                dtAcc.DataSource = cB.GetListTop10();
                dtAcc.DataBind();

                // load thong tin
                Accessory c = new Accessory();
                c = cB.GetById(id);
                lblName.Text = c.accesNames;
                lblPrice.Text = string.Format(System.Globalization.CultureInfo.CreateSpecificCulture("vi-VN"), "{0:#,## VNĐ}", c.accesPrice);
                lblDetails.Text = c.accesDetails;
                imghinh.ImageUrl = c.accesImages;
                lbllensFocallensgth.Text = c.accesUse;

                dtAcc.Visible = true;
                pnAcc.Visible = true;
                dtAcc.DataBind();
                pnAcc.DataBind();
            }

            
            
           
        }

        protected void btnGioHang_Click(object sender, EventArgs e)
        {
            string cate = Request.QueryString["cate"].ToString();
            int id = int.Parse(Request.QueryString["id"].ToString()); 
            //Image lblimage = (Image)lbtn.Parent.FindControl("imgProduct");
            Session["lblimage"] = imghinh.ImageUrl;
            Response.Redirect("/ThemVaoGioHang.aspx?cate="+ cate +"&ID=" + id);
        }
         
    }
}